package com.forekenow.demo;

import java.util.Scanner;

public class bank {
    public static String name="admin";
    public static String password="123";
    public static double money=18000;
    public static double total;
    public static void main(String[] args) {
        bank.login();

        if(bank.islogin()){
            bank.menu();
        }
    }
    public static boolean islogin(){
       int a =2;
        for (int i=0;i<=2;i++) {
           Scanner sc = new Scanner(System.in);
           System.out.println("请输入账号");
           String ac = sc.next();
           System.out.println("请输入密码");
           String ps = sc.next();
           if (name.equals(ac) && password.equals(ps)) {
               return true;
           }
           else {
               System.out.println("您还有"+a--+"次机会");
               if (a==-1){
                   System.out.println("账号已被紧急封禁，联系工作人员解锁");
               }
           }
        }
        return false;

    }
    public static void login(){
        System.out.println("-------------------");
        System.out.println("****  欢迎登陆  ****");
        System.out.println("--------------------");

    }

    public static void menu() {
        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("1.查询；2.存款；3.取款；4.修改密码；5.退出");
            int opt = sc.nextInt();
            switch (opt){
                case 1:
                    checkmoney();
                    break;
                case 2:
                    addmoney();
                    break;
                case 3:
                    outmoney();
                    break;
                case 4:
                    recode();
                    break;
                case 5:
                    System.exit(0);
            }
            System.out.println("是否使用其他服务输入Y继续，N停止");
            String restart = sc.next();
            if (restart.equals("N")||restart.equals("n")){
                System.out.println("感谢使用");
                System.exit(0);
            }

        }
    }

    private static void recode() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要更改的账号");
        String ac = sc.next();
        System.out.println("请输入原始密码");
        String ps = sc.next();
        if (name.equals(ac) && password.equals(ps)) {
            System.out.println("请输入六位数新密码");
            password = sc.next();
            System.out.println("修改密码成功！");
            System.out.println("请重新输入新密码进行登录！:");
            String re = sc.next();
            if (password.equals(re)){
                System.out.println("登录成功");
                bank.menu();
            }
        }else {
            System.out.println("密码不匹配！程序退出");
            System.exit(0);
        }
    }

    public static void checkmoney(){
        System.out.println("账户余额:"+money);
    }

    public static void addmoney(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入存款金额");
        double add = sc.nextInt();
        total = money+add;
        System.out.println("存款成功，账户余额为："+total);
    }
    public static void outmoney(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入取款金额");
        double out = sc.nextInt();
        double a=total-out;
        System.out.println("取款成功，账户余额为："+a);
    }




}
